<template>
    <div id="movieDetail">
        <md-content v-if="mDetail" class="md-scrollbar">
            <div class="one">
                <div class="header">
                    <md-list class="md-triple-line">
                        <md-list-item>
                            <div class="md-list-item-text">
                                <div>{{mDetail.title}}<span class="threeD">3D</span><span class="imax">IMAX</span></div>
                                <span class="original">{{mDetail.original_title}}</span>
                                <span><span class="genres" :key="i" v-for="(r,i) in mDetail.genres">{{r}}</span></span>
                                <span>{{mDetail.countries[0]}} | {{mDetail.year}}</span>
                            </div>
                            <md-avatar>
                            <img :src="mDetail.images.medium" alt="People"> 
                            </md-avatar>
                        </md-list-item>
                    </md-list>
                </div>
                <div class="rating">
                    <div class="rating_item ping">
                        <div>{{mDetail.rating.average}}<md-icon :key="i" v-for="i in 5">star</md-icon></div>
                        <div>观众评分{{mDetail.ratings_count}}人</div>
                    </div>
                    <div class="rating_item">
                        <div>{{mDetail.reviews_count}}</div>
                        <div>已看人数</div>
                    </div>
                    <div class="rating_item">
                        <div>{{mDetail.wish_count}}</div>
                        <div>想看人数</div>
                    </div>
                </div>
                <div class="button">
                    <md-button @click="changeBtn(1)" v-bind:class="{ btnTheme: isActive1}"><md-icon :class="{iconTheme:isActive1}">favorite</md-icon>想看</md-button>
                    <md-button @click="changeBtn(2)" v-bind:class="{ btnTheme: isActive2}"><md-icon :class="{iconTheme:isActive2}">star</md-icon>看过</md-button>
                </div>
                <div class="summary">
                    {{mDetail.summary}}
                </div>
            </div>
            <div class="two">
                <div>观影提示</div>
                <div><md-icon>description</md-icon>會議殺做出新高度！看完這篇更懂恐龍世界</div>
                <div><md-icon>info</md-icon>片尾字幕結束處有彩蛋</div>
            </div>
            <div class="three">
                <div>演职人员</div>
                <div class="people">
                    <swiper :options="swiperOption" ref="mySwiper">
                        <!-- slides -->
                        <swiper-slide :key="r.id" v-for="r in mDetail.casts">
                            <img class="swiperImg" :src="mDetail.images.medium" alt="People">
                            <span>{{r.name}}</span> 
                        </swiper-slide>
                        <!-- Optional controls -->
                        <!-- <div class="swiper-scrollbar"   slot="scrollbar"></div> -->
                    </swiper>
                </div>
            </div>
        </md-content>
    </div>
</template>
<script>
import { mapState, mapActions } from "vuex";
export default {
  name: "mDetail",
  data() {
    return {
      swiperOption: {
        initialSlide: 0, //设定初始化时slide的索引
        direction: "horizontal", //Slides的滑动方向，可设置水平(horizontal)或垂直(vertical)。
        loop: false, //无限滚动
        centeredSlides: true,
        spaceBetween: 5,
        width: 90,
        autoHeight: 140,
        onSlideChangeEnd: swiper => {
          console.log("onSlideChangeEnd", swiper.realIndex);
        }
      },
      isActive1: false,
      isActive2: false
    };
  },
  computed: {
    ...mapState({
      mId: state => state.mId,
      mDetail: state => state.mDetail
    })
  },
  mounted() {
    this.$nextTick(function() {
      this.getByMoviesId({ mId: this.mId });
    });
  },
  methods: {
    ...mapActions({
      getByMoviesId: "GET_BYMOVIESID"
    }),
    changeBtn(flag) {
      if (flag == 1) this.isActive1 = !this.isActive1;
      else this.isActive2 = !this.isActive2;
    }
  }
};
</script>
<style lang="less" scoped>
@import "../styles/var";
#movieDetail {
  background: @lightGray;
  .one {
    background: @bodyColor;
    .header {
      width: 100%;
      height: auto;
      background: @zong;
      padding-top: 15px;
      .md-list-item-text {
        div {
          font-size: @mediumSize;
          font-weight: bold;
          span {
            display: inline-block;
            color: @bodyColor;
            padding: 1px 2px;
            font-weight: normal;
            height: 20px;
            line-height: 18px;
            text-align: center;
          }
          .threeD {
            background: @lightZong;
            margin-left: 5px;
            width: 25px;
          }
          .imax {
            width: 45px;
            border: 1px solid @lightZong;
          }
        }
        span {
          font-size: @smallSize;
          padding: 2px;
        }
        .original {
          font-style: italic;
          margin: 5px 0;
        }
        .genres + .genres:before {
          content: "/";
          margin-right: 5px;
        }
      }
    }
    .rating {
      display: -webkit-flex;
      display: flex;
      justify-content: space-around;
      align-items: center;
      margin: 5px 0;
      .rating_item {
        text-align: center;
        width: 100px;
        & > div:nth-child(1) {
          font-weight: bold;
        }
        & > div:nth-child(2) {
          font-size: @smallestSize;
          color: @gray;
        }
      }
      .ping {
        width: 150px;
        .md-icon {
          font-size: @normalSize !important;
          color: @rating;
          display: inline;
        }
      }
    }
    .button {
      display: -webkit-flex;
      display: flex;
      justify-content: space-around;
      align-items: center;
      margin: 5px 0;
      .md-button {
        background: @lightGray;
        width: 120px;
        color: @lighterzong;
        .md-icon {
          font-size: @mediumSize !important;
        }
      }
      .btnTheme {
        background: @lightOranger;
        border: 1px solid @OrangerBorder;
      }
      .iconTheme {
        color: @red;
      }
    }
    .summary {
      padding: 0 8px 15px 8px;
      line-height: 24px;
      font-size: @smallSize;
    }
  }
  .two {
    background: @bodyColor;
    margin-top: 15px;
    padding: 15px 8px;
    div {
      height: 30px;
      font-size: @smallSize;
      .md-icon {
        font-size: @smallSize !important;
      }
    }
    & > div:nth-child(1) {
      font-weight: bold;
    }
  }
  .three {
    background: @bodyColor;
    margin-top: 15px;
    padding: 15px 8px;
    & > div:nth-child(1) {
      font-weight: bold;
    }
    .people {
      text-align: center;
      .swiperImg {
        width: 90px;
        height: 110px;
      }
    }
  }
}
@media screen and (max-width: 414px) {
  .md-avatar {
    border-radius: 0;
    width: 90px;
    height: 110px;
  }
  .md-content {
    max-height: 550px;
    overflow: auto;
  }
}
@media screen and (max-width: 375px) {
  .md-avatar {
    border-radius: 0;
    width: 80px;
    height: 100px;
  }
  .md-content {
    max-height: 550px;
    overflow: auto;
  }
}
@media screen and (max-width: 320px) {
  .md-avatar {
    border-radius: 0;
    width: 70px;
    height: 90px;
  }
  .md-content {
    max-height: 450px;
    overflow: auto;
  }
}
</style>


